Skip to content

Add wolfBoot support for STM32G4#777

Open
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:stm32g4
Open

Add wolfBoot support for STM32G4#777
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:stm32g4

Conversation

@dgarske
Copy link
Copy Markdown
Member

@dgarske dgarske commented May 12, 2026

  • New bare-register HAL for STM32G4 single-bank parts (G491, G471, G4A1), verified on NUCLEO-G491RE: 512 KB flash, 96 KB SRAM, Cortex-M4F.
  • Register map (RCC, PWR, FLASH, GPIOA, LPUART1) lives in hal/stm32g4.h so the wolfBoot HAL and the test-app share one definition.
  • Clock brought up to 170 MHz using HSI16 + PLL with PWR Range 1 Boost (RM0440 6.1.4), 4 flash wait states, prefetch + I/D-cache enabled.
  • Default config signs with ECC256/SHA256 and partitions 512 KB as 32 K boot / 232 K app / 232 K update / 16 K swap.
  • Test app uses printf via test-app/syscalls.c (routes _write -> uart_write), so v1/v2 boot logs and wolfBoot_success() confirmation print over the ST-LINK VCP.
  • Optional DEBUG_UART=1 enables wolfBoot's own boot logs on LPUART1 PA2/PA3 AF12 (NUCLEO ST-LINK VCP) at 115200.
  • CI matrix entry added to .github/workflows/test-configs.yml.

@dgarske dgarske self-assigned this May 12, 2026
Copilot AI review requested due to automatic review settings May 12, 2026 17:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds wolfBoot target support for STM32G4 (verified on NUCLEO-G491RE), including a new HAL, linker script, test application integration, and documentation updates.

Changes:

  • Introduces STM32G4 HAL (clock bring-up, flash IAP, optional debug UART) and linker script.
  • Adds STM32G4 test app support (LED + UART/printf) and build system wiring.
  • Documents STM32G4 configuration, memory layout, flashing, and debugging steps; adds CI build coverage for the new example config.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
test-app/led.c Adds STM32G4-specific boot LED on/off implementation for NUCLEO-G491RE.
test-app/app_stm32g4.c New bare-metal STM32G4 test app (LED blink + update confirmation + printf).
test-app/Makefile Adds STM32G4 build flags and ensures syscalls/printf linkage.
hal/stm32g4.ld New STM32G4 linker script (FLASH/RAM layout and sections).
hal/stm32g4.h New STM32G4 register/bit definitions and UART/board pin constants.
hal/stm32g4.c New STM32G4 HAL implementation (clock, flash write/erase, UART).
docs/Targets.md Adds STM32G4 target documentation (config, layout, flashing/debugging).
config/examples/stm32g4.config Adds a reference STM32G4 configuration and partition layout.
arch.mk Adds STM32G4 ARCH_FLASH_OFFSET configuration.
.github/workflows/test-configs.yml Adds CI build job for stm32g4 example config.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread hal/stm32g4.c
Comment thread hal/stm32g4.c
Comment thread hal/stm32g4.h
Comment thread test-app/led.c Outdated
Comment thread test-app/led.c
Comment thread hal/stm32g4.c Outdated
Comment thread hal/stm32g4.ld
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.

Comment thread hal/stm32g4.c
Comment on lines +66 to +75
int off = (address + i) - (((address + i) >> 3) << 3);
uint32_t base_addr = address & (~0x07); /* aligned to 64 bit */
int u32_idx = (i >> 2);
dst = (uint32_t *)(base_addr);
val[0] = dst[u32_idx];
val[1] = dst[u32_idx + 1];
while ((off < 8) && (i < len))
vbytes[off++] = data[i++];
dst[u32_idx] = val[0];
dst[u32_idx + 1] = val[1];
Comment thread hal/stm32g4.c
Comment on lines +116 to +127
end_address = address + len - 1;
for (p = address; p < end_address; p += FLASH_PAGE_SIZE) {
flash_wait_complete();
flash_clear_errors();
page_number = (p >> 11) & FLASH_CR_PNB_MASK;
reg = FLASH_CR & ~(FLASH_CR_PNB_MASK << FLASH_CR_PNB_SHIFT);
FLASH_CR = reg | (page_number << FLASH_CR_PNB_SHIFT) | FLASH_CR_PER;
DMB();
FLASH_CR |= FLASH_CR_STRT;
flash_wait_complete();
FLASH_CR &= ~FLASH_CR_PER;
}
Comment thread hal/stm32g4.h
Comment on lines +34 to +36
#define DMB() __asm__ volatile ("dmb")
#define ISB() __asm__ volatile ("isb")
#define DSB() __asm__ volatile ("dsb")
Comment thread hal/stm32g4.c
Comment on lines +37 to +43
static void RAMFUNCTION flash_clear_errors(void)
{
FLASH_SR |= (FLASH_SR_OPERR | FLASH_SR_PROGERR | FLASH_SR_WRPERR |
FLASH_SR_PGAERR | FLASH_SR_SIZERR | FLASH_SR_PGSERR |
FLASH_SR_MISERR | FLASH_SR_FASTERR | FLASH_SR_RDERR |
FLASH_SR_OPTVERR);
}
Comment thread hal/stm32g4.c
for (i = 0; i < len; i++) {
while ((LPUART1_ISR & USART_ISR_TXE) == 0)
;
LPUART1_TDR = (uint32_t)buf[i];
Comment thread hal/stm32g4.ld
Comment on lines +19 to +23
.edidx :
{
. = ALIGN(4);
*(.ARM.exidx*)
} > FLASH
Comment thread test-app/led.c
reg = GPIOA_MODER & ~(0x03 << (pin * 2));
GPIOA_MODER = reg | (1 << (pin * 2));
reg = GPIOA_PUPDR & ~(0x03 << (pin * 2));
GPIOA_PUPDR = reg | (1 << (pin * 2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants